var main_vm = new Vue({
    el: 'main',
    data: {
        keywords: null,
        query: null,
        list: [],
        total: null,
        current_page: 1,
        last_page: 1,
        turn_page: 1
    },
    computed: {
        token() {
            return localStorage.token || Cookies.get('token')
        },
        id() {
            return Url.queryString('id')
        }
    },
    watch: {
        keywords(val) {
            if (val == "" || val == null) {
                this.query = null
            }
        },

    },
    methods: {
        getList() {
            var self = this
            axios.get(window.config.host + '/year_scores', {
                    headers: {
                        Authorization: 'Bearer ' + this.token
                    },
                    params: {
                        id: this.id,
                        name: this.query,
                        page: this.current_page
                    }
                })
                .then(function(res) {
                    console.log(res);
                    if (res.status == 200) {
                        self.list = res.data.data.data
                        self.total = res.data.data.total
                        self.current_page = res.data.data.current_page
                        self.last_page = res.data.data.last_page
                    } else {
                        alert(res.data.message)
                    }
                })
                .catch(function(err) {

                })
                .then(function() {

                })
        },
        search() {
            this.query = this.keywords
            this.current_page = 1
            this.getList()
        },
        pageTurn(num) {
            this.current_page = this.current_page + num
            this.getList()
        },
        toPage() {
            if (this.turn_page <= this.total) {
                this.current_page = this.turn_page
                this.getList()
            }
        }
    },
    mounted() {
        this.getList()
    }
})